#ifndef SHBK_COMMOM_INICONFIG_H_
#define SHBK_COMMOM_INICONFIG_H_
#include <string>
#include <stdio.h>
//Store ini file config information
typedef struct st_env_config{
    st_env_config() = default;
    st_env_config(const std::string &db_ip, const unsigned short db_port, 
    const std::string &db_user, const std::string &db_pwd, 
    const std::string &db_name, const unsigned short server_port, 
    const unsigned short read_tv_sec, const unsigned short read_tv_usec,
    const unsigned short write_tv_sec, const unsigned short write_tv_usec,
    const unsigned short max_conn, const unsigned short min_conn,
    const unsigned short conn_timeout, const unsigned short conn_free_time){
        this->db_ip = db_ip;
        this->db_port = db_port;
        this->db_user = db_user;
        this->db_pwd = db_pwd;
        this->db_name = db_name;

        this->server_port = server_port;

        this->read_tv_sec = read_tv_sec;
        this->read_tv_usec = read_tv_usec;
        this->write_tv_sec = write_tv_sec;
        this->write_tv_usec = write_tv_usec;

        this->max_conn = max_conn;
        this->min_conn = min_conn;
        this->conn_timeout = conn_timeout;
        this->conn_free_time = conn_free_time;
    }
    st_env_config &operator=(st_env_config config){
        if(this != &config){
            this->db_ip = config.db_ip;
            this->db_port = config.db_port;
            this->db_user = config.db_user;
            this->db_pwd = config.db_pwd;
            this->db_name = config.db_name;

            this->server_port = config.server_port;

            this->read_tv_sec = config.read_tv_sec;
            this->read_tv_usec = config.read_tv_usec;
            this->write_tv_sec = config.write_tv_sec;
            this->write_tv_usec = config.write_tv_usec;

            this->max_conn = max_conn;
            this->min_conn = min_conn;
            this->conn_timeout = conn_timeout;
            this->conn_free_time = conn_free_time;

        }
        return *this;
    }
    virtual ~st_env_config(){}
    //DataBase config
    std::string db_ip;
    unsigned short db_port;
    std::string db_user;
    std::string db_pwd; 
    std::string db_name;

    //Server config
    unsigned short server_port;

    //timeout config
    unsigned short read_tv_sec;
    unsigned short read_tv_usec;
    unsigned short write_tv_sec;
    unsigned short write_tv_usec;

    //database conn pool config
    unsigned short max_conn;
    unsigned short min_conn;
    unsigned short conn_timeout;    
    unsigned short conn_free_time;

}_st_env_config;

class IniConfig{
public:
    IniConfig();
    virtual ~IniConfig();
    bool loadfile(const std::string &filepath);
    _st_env_config &getconfig();
private:
    _st_env_config _config;
    bool _isloaded;
};
#endif
